package com.hnevc.trafficexpanedlistviewdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/12/14.
 */

public class MyBaseAdapter extends BaseAdapter {
    Context mContext;
    List<BusInfo> mBusInfoList;

    public MyBaseAdapter(Context context, List<BusInfo> busInfoList) {
        mContext = context;
        mBusInfoList = busInfoList;

    }

    @Override
    public int getCount() {
        return mBusInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return mBusInfoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return mBusInfoList.get(i).getBusId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        view = LayoutInflater.from(mContext).inflate(R.layout.list_item,null);

        BusInfo busInfo = mBusInfoList.get(i);
        TextView mTvBusName = (TextView) view.findViewById(R.id.id_busname);
        mTvBusName.setText(busInfo.getBusId()+"号");
        TextView mTvBusRenshu = (TextView) view.findViewById(R.id.id_bus_renshu);
        mTvBusRenshu.setText("("+busInfo.getPersonNum()+"人）");
        TextView mTvDistance = (TextView) view.findViewById(R.id.id_bus_arrivedistance);
        mTvDistance.setText("距离站台"+busInfo.getDistance()+"米");
        TextView mTvArriveTime = (TextView) view.findViewById(R.id.id_bus_arrivetime);
        mTvArriveTime.setText(busInfo.getArriveTime()+"分钟到达");
        return view;
    }
}
